package br.com.registrofinancas.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import br.com.registrofinancas.R;
import br.com.registrofinancas.database.CategoriasDAO;
import br.com.registrofinancas.database.MovimentosDAO;

public class ExcludeActivity extends Activity implements OnClickListener {

	private Dialog dialog;
	private Intent intent;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_exclude_backup);
		
		
		dialog = new Dialog(this);
		dialog.setContentView(R.layout.backup_exclude_dialog);
		dialog.setTitle("Excluir Dados");
		TextView tvMessage = (TextView) dialog.findViewById(R.id.backup_exlude_dialog_tx_message);
		tvMessage.setText("Deseja todos os registros de finanças?");
		Button buttonOk = (Button) dialog.findViewById(R.id.backup_exclude_dialog_bt_OK);
		Button buttonCancel = (Button) dialog.findViewById(R.id.backup_exclude_dialog_bt_Cancel);
		buttonOk.setOnClickListener(this);
		buttonCancel.setOnClickListener(this);
		dialog.show();
		
	}

	@Override
	public void onClick(View v) {
		
		if(v.getId() == R.id.backup_exclude_dialog_bt_OK){
			CategoriasDAO categorias = new CategoriasDAO(this);
			MovimentosDAO movimentos = new MovimentosDAO(this);
			categorias.deleteAll();
			movimentos.deleteAll();
			Toast.makeText(this, "Registros deletados", Toast.LENGTH_LONG).show();
			goBack();
		}else
		{
			dialog.dismiss();
			goBack();
		}
		
	}
	
	public void goBack()
	{
		intent = new Intent(this, MenuActivity.class);
		startActivity(intent);
	}
			
}
